from django.db import models
from django.contrib.auth.models import User
from api.good.models import Goods


class Cart(models.Model):
    id = models.AutoField(primary_key=True)
    quantity = models.IntegerField(default=0, verbose_name='商品总数')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户ID')
    good = models.ForeignKey(Goods, on_delete=models.DO_NOTHING, verbose_name='商品ID')
    total_amount = models.DecimalField(max_digits=10, decimal_places=2, default=0)

    def __str__(self):
        return str(self.id)+str(self.user)

    class Meta:
        verbose_name_plural = '购物车管理'
        db_table = 'tb_cart'

